package com.regex.web.controller.community;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;

public class SysJsonController {
	// json字符串-简单对象型
	private static final String JSON_OBJ_STR = "{\r\n" + 
			"    \"ZhuCeLeiXing\":\"企业\",\r\n" + 
			"    \"LiShuGuanXi\":\"市（地）\",\r\n" + 
			"    \"YinXingZhangHao\":\"1801014170037683\",\r\n" + 
			"    \"LianXiDianHua1\":\"15778009312\",\r\n" + 
			"    \"LianXiRen\":\"陈玉珍\",\r\n" + 
			"    \"DanWeiLeiXing\":\"企业\",\r\n" + 
			"    \"TianBiaoRen\":\"陈玉珍\",\r\n" + 
			"    \"TongYiSheHuiXinYongDaiMa\":\"91440300192287527J\",\r\n" + 
			"    \"DanWeiSheBaoBianHao\":\"705164\",\r\n" + 
			"    \"NaShuiShiBieHao\":\"91440300192287527J\",\r\n" + 
			"    \"KaiHuXing\":\"民生银行深圳分行营业部\",\r\n" + 
			"    \"FaRenDaiBiao\":\"郭瑾\",\r\n" + 
			"    \"NianDu\":\"2020\",\r\n" + 
			"    \"HuiJiZhiDu\":\"股份制\",\r\n" + 
			"    \"DanWeiChuanZhen\":\"83258703\",\r\n" + 
			"    \"DianZiYouJian\":\"weiye@szweiye.com\",\r\n" + 
			"    \"MAIN_TBL_PK\":\"20210322161127385700\",\r\n" + 
			"    \"JingYingZhuangKuang\":\"经营\",\r\n" + 
			"    \"DanWeiMingChen\":\"深圳市维业装饰集团股份有限公司\",\r\n" + 
			"    \"ShangJiZhuGuan\":\"/\",\r\n" + 
			"    \"DanWeiDiZhi\":\"深圳市福田区新洲路以西、莲花路以南振业景洲大厦裙楼101\",\r\n" + 
			"    \"LianXiDianHua\":\"83260088\",\r\n" + 
			"    \"XingYeFenLei\":\"建筑业\",\r\n" + 
			"    \"drow20181999103670645\":[\r\n" + 
			"        {\r\n" + 
			"            \"ShenFenZhengHao\":\"441523199812186011\",\r\n" + 
			"            \"FaZhengShiJian\":\"2014-01-03 00:00:00\",\r\n" + 
			"            \"HuJiLeiXing\":\"深户\",\r\n" + 
			"            \"JunCanDengJi\":\"一级\",\r\n" + 
			"            \"HunYinZhuangKuang\":\"未婚\",\r\n" + 
			"            \"gwmc1\":\"办事人员和有关人员\",\r\n" + 
			"            \"WenHuaChengDu\":\"高中\",\r\n" + 
			"            \"SheBaoDianNaoHao\":\"606576271\",\r\n" + 
			"            \"gwmc3\":\"行政事务人员\",\r\n" + 
			"            \"ZhuangTai\":\"1\",\r\n" + 
			"            \"gwmc2\":\"行政办公人员\",\r\n" + 
			"            \"ZaiGangQingKuang\":\"1\",\r\n" + 
			"            \"GangWeiMingChen2\":\"行政办公人员\",\r\n" + 
			"            \"JiuYeYueFen\":\"1,2,3,4,5,6,7,8,9,10,11,12\",\r\n" + 
			"            \"BenDanWeiJiuYeQiShiShiJian\":\"2020-01-01\",\r\n" + 
			"            \"XingBie\":\"男\",\r\n" + 
			"            \"JinJiLianXiRenDianHua\":\"\",\r\n" + 
			"            \"GangWeiMingChen\":\"办事人员和有关人员\",\r\n" + 
			"            \"ZhiChenDengJi\":\"无\",\r\n" + 
			"            \"GangWeiMingChen3\":\"行政事务人员\",\r\n" + 
			"            \"JunCanZhengHao\":\"\",\r\n" + 
			"            \"dynWidgetName\":\"a14445\",\r\n" + 
			"            \"HuKouDiZhi\":\"广东省深圳市南山区西丽路54号雅丽阁306\",\r\n" + 
			"            \"MinZu\":\"汉族\",\r\n" + 
			"            \"XingMing\":\"陈石和\",\r\n" + 
			"            \"JiGuan\":\"广东深圳\",\r\n" + 
			"            \"JinJiLianXiRenXingMing\":\"陈显砖\",\r\n" + 
			"            \"CanJiDengJi\":\"四级\",\r\n" + 
			"            \"AiHaoTeChang\":\"\",\r\n" + 
			"            \"JiaTingZhuZhi\":\"13602695161\",\r\n" + 
			"            \"ShiFuJunCan\":\"0\",\r\n" + 
			"            \"ChuShengRiQi\":\"1998-12-18\",\r\n" + 
			"            \"CanJiLeiBie\":\"智力\",\r\n" + 
			"            \"DianHuaLianXi\":\"13602695161\",\r\n" + 
			"            \"CanJiRenZhengHao\":\"44152319981218601154\",\r\n" + 
			"            \"YueShouRu\":\"2200\"\r\n" + 
			"        },\r\n" + 
			"        {\r\n" + 
			"            \"ShenFenZhengHao\":\"44030619811218002X\",\r\n" + 
			"            \"FaZhengShiJian\":\"2021-02-22 09:56:11\",\r\n" + 
			"            \"HuJiLeiXing\":\"深户\",\r\n" + 
			"            \"JunCanDengJi\":\"一级\",\r\n" + 
			"            \"HunYinZhuangKuang\":\"已婚\",\r\n" + 
			"            \"gwmc1\":\"办事人员和有关人员\",\r\n" + 
			"            \"WenHuaChengDu\":\"高中\",\r\n" + 
			"            \"SheBaoDianNaoHao\":\"606576271\",\r\n" + 
			"            \"gwmc3\":\"行政事务人员\",\r\n" + 
			"            \"ZhuangTai\":\"1\",\r\n" + 
			"            \"gwmc2\":\"行政办公人员\",\r\n" + 
			"            \"ZaiGangQingKuang\":\"1\",\r\n" + 
			"            \"GangWeiMingChen2\":\"行政办公人员\",\r\n" + 
			"            \"JiuYeYueFen\":\"1,2,3,4,5,6,7,8,9,10,11,12\",\r\n" + 
			"            \"BenDanWeiJiuYeQiShiShiJian\":\"2008-02-01\",\r\n" + 
			"            \"XingBie\":\"女\",\r\n" + 
			"            \"JinJiLianXiRenDianHua\":\"13715060892\",\r\n" + 
			"            \"GangWeiMingChen\":\"办事人员和有关人员\",\r\n" + 
			"            \"ZhiChenDengJi\":\"无\",\r\n" + 
			"            \"GangWeiMingChen3\":\"行政事务人员\",\r\n" + 
			"            \"JunCanZhengHao\":\"\",\r\n" + 
			"            \"dynWidgetName\":\"a14445\",\r\n" + 
			"            \"HuKouDiZhi\":\"广东省深圳市宝安区上川路宝城三十一区上川市场502\",\r\n" + 
			"            \"MinZu\":\"汉族\",\r\n" + 
			"            \"XingMing\":\"张玉洁\",\r\n" + 
			"            \"JiGuan\":\"广东深圳\",\r\n" + 
			"            \"JinJiLianXiRenXingMing\":\"张汉洪\",\r\n" + 
			"            \"CanJiDengJi\":\"二级\",\r\n" + 
			"            \"AiHaoTeChang\":\"\",\r\n" + 
			"            \"JiaTingZhuZhi\":\"广东省深圳市福田区莲花街道香梅路香蜜新村6栋E5\",\r\n" + 
			"            \"ShiFuJunCan\":\"0\",\r\n" + 
			"            \"ChuShengRiQi\":\"1981-12-18\",\r\n" + 
			"            \"CanJiLeiBie\":\"肢体\",\r\n" + 
			"            \"DianHuaLianXi\":\"13715060892\",\r\n" + 
			"            \"CanJiRenZhengHao\":\"44030619811218002X42\",\r\n" + 
			"            \"YueShouRu\":\"3800\"\r\n" + 
			"        }\r\n" + 
			"    ]\r\n" + 
			"}";
	// json字符串-数组类型
	private static final String JSON_ARRAY_STR = "[{\r\n" + 
			"    \"ZhuCeLeiXing\":\"企业\",\r\n" + 
			"    \"LiShuGuanXi\":\"市（地）\",\r\n" + 
			"    \"YinXingZhangHao\":\"1801014170037683\",\r\n" + 
			"    \"LianXiDianHua1\":\"15778009312\",\r\n" + 
			"    \"LianXiRen\":\"陈玉珍\",\r\n" + 
			"    \"DanWeiLeiXing\":\"企业\",\r\n" + 
			"    \"TianBiaoRen\":\"陈玉珍\",\r\n" + 
			"    \"TongYiSheHuiXinYongDaiMa\":\"91440300192287527J\",\r\n" + 
			"    \"DanWeiSheBaoBianHao\":\"705164\",\r\n" + 
			"    \"NaShuiShiBieHao\":\"91440300192287527J\",\r\n" + 
			"    \"KaiHuXing\":\"民生银行深圳分行营业部\",\r\n" + 
			"    \"FaRenDaiBiao\":\"郭瑾\",\r\n" + 
			"    \"NianDu\":\"2020\",\r\n" + 
			"    \"HuiJiZhiDu\":\"股份制\",\r\n" + 
			"    \"DanWeiChuanZhen\":\"83258703\",\r\n" + 
			"    \"DianZiYouJian\":\"weiye@szweiye.com\",\r\n" + 
			"    \"MAIN_TBL_PK\":\"20210322161127385700\",\r\n" + 
			"    \"JingYingZhuangKuang\":\"经营\",\r\n" + 
			"    \"DanWeiMingChen\":\"深圳市维业装饰集团股份有限公司\",\r\n" + 
			"    \"ShangJiZhuGuan\":\"/\",\r\n" + 
			"    \"DanWeiDiZhi\":\"深圳市福田区新洲路以西、莲花路以南振业景洲大厦裙楼101\",\r\n" + 
			"    \"LianXiDianHua\":\"83260088\",\r\n" + 
			"    \"XingYeFenLei\":\"建筑业\",\r\n" + 
			"    \"drow20181999103670645\":[\r\n" + 
			"        {\r\n" + 
			"            \"ShenFenZhengHao\":\"441523199812186011\",\r\n" + 
			"            \"FaZhengShiJian\":\"2014-01-03 00:00:00\",\r\n" + 
			"            \"HuJiLeiXing\":\"深户\",\r\n" + 
			"            \"JunCanDengJi\":\"一级\",\r\n" + 
			"            \"HunYinZhuangKuang\":\"未婚\",\r\n" + 
			"            \"gwmc1\":\"办事人员和有关人员\",\r\n" + 
			"            \"WenHuaChengDu\":\"高中\",\r\n" + 
			"            \"SheBaoDianNaoHao\":\"606576271\",\r\n" + 
			"            \"gwmc3\":\"行政事务人员\",\r\n" + 
			"            \"ZhuangTai\":\"1\",\r\n" + 
			"            \"gwmc2\":\"行政办公人员\",\r\n" + 
			"            \"ZaiGangQingKuang\":\"1\",\r\n" + 
			"            \"GangWeiMingChen2\":\"行政办公人员\",\r\n" + 
			"            \"JiuYeYueFen\":\"1,2,3,4,5,6,7,8,9,10,11,12\",\r\n" + 
			"            \"BenDanWeiJiuYeQiShiShiJian\":\"2020-01-01\",\r\n" + 
			"            \"XingBie\":\"男\",\r\n" + 
			"            \"JinJiLianXiRenDianHua\":\"\",\r\n" + 
			"            \"GangWeiMingChen\":\"办事人员和有关人员\",\r\n" + 
			"            \"ZhiChenDengJi\":\"无\",\r\n" + 
			"            \"GangWeiMingChen3\":\"行政事务人员\",\r\n" + 
			"            \"JunCanZhengHao\":\"\",\r\n" + 
			"            \"dynWidgetName\":\"a14445\",\r\n" + 
			"            \"HuKouDiZhi\":\"广东省深圳市南山区西丽路54号雅丽阁306\",\r\n" + 
			"            \"MinZu\":\"汉族\",\r\n" + 
			"            \"XingMing\":\"陈石和\",\r\n" + 
			"            \"JiGuan\":\"广东深圳\",\r\n" + 
			"            \"JinJiLianXiRenXingMing\":\"陈显砖\",\r\n" + 
			"            \"CanJiDengJi\":\"四级\",\r\n" + 
			"            \"AiHaoTeChang\":\"\",\r\n" + 
			"            \"JiaTingZhuZhi\":\"13602695161\",\r\n" + 
			"            \"ShiFuJunCan\":\"0\",\r\n" + 
			"            \"ChuShengRiQi\":\"1998-12-18\",\r\n" + 
			"            \"CanJiLeiBie\":\"智力\",\r\n" + 
			"            \"DianHuaLianXi\":\"13602695161\",\r\n" + 
			"            \"CanJiRenZhengHao\":\"44152319981218601154\",\r\n" + 
			"            \"YueShouRu\":\"2200\"\r\n" + 
			"        },\r\n" + 
			"        {\r\n" + 
			"            \"ShenFenZhengHao\":\"44030619811218002X\",\r\n" + 
			"            \"FaZhengShiJian\":\"2021-02-22 09:56:11\",\r\n" + 
			"            \"HuJiLeiXing\":\"深户\",\r\n" + 
			"            \"JunCanDengJi\":\"一级\",\r\n" + 
			"            \"HunYinZhuangKuang\":\"已婚\",\r\n" + 
			"            \"gwmc1\":\"办事人员和有关人员\",\r\n" + 
			"            \"WenHuaChengDu\":\"高中\",\r\n" + 
			"            \"SheBaoDianNaoHao\":\"606576271\",\r\n" + 
			"            \"gwmc3\":\"行政事务人员\",\r\n" + 
			"            \"ZhuangTai\":\"1\",\r\n" + 
			"            \"gwmc2\":\"行政办公人员\",\r\n" + 
			"            \"ZaiGangQingKuang\":\"1\",\r\n" + 
			"            \"GangWeiMingChen2\":\"行政办公人员\",\r\n" + 
			"            \"JiuYeYueFen\":\"1,2,3,4,5,6,7,8,9,10,11,12\",\r\n" + 
			"            \"BenDanWeiJiuYeQiShiShiJian\":\"2008-02-01\",\r\n" + 
			"            \"XingBie\":\"女\",\r\n" + 
			"            \"JinJiLianXiRenDianHua\":\"13715060892\",\r\n" + 
			"            \"GangWeiMingChen\":\"办事人员和有关人员\",\r\n" + 
			"            \"ZhiChenDengJi\":\"无\",\r\n" + 
			"            \"GangWeiMingChen3\":\"行政事务人员\",\r\n" + 
			"            \"JunCanZhengHao\":\"\",\r\n" + 
			"            \"dynWidgetName\":\"a14445\",\r\n" + 
			"            \"HuKouDiZhi\":\"广东省深圳市宝安区上川路宝城三十一区上川市场502\",\r\n" + 
			"            \"MinZu\":\"汉族\",\r\n" + 
			"            \"XingMing\":\"张玉洁\",\r\n" + 
			"            \"JiGuan\":\"广东深圳\",\r\n" + 
			"            \"JinJiLianXiRenXingMing\":\"张汉洪\",\r\n" + 
			"            \"CanJiDengJi\":\"二级\",\r\n" + 
			"            \"AiHaoTeChang\":\"\",\r\n" + 
			"            \"JiaTingZhuZhi\":\"广东省深圳市福田区莲花街道香梅路香蜜新村6栋E5\",\r\n" + 
			"            \"ShiFuJunCan\":\"0\",\r\n" + 
			"            \"ChuShengRiQi\":\"1981-12-18\",\r\n" + 
			"            \"CanJiLeiBie\":\"肢体\",\r\n" + 
			"            \"DianHuaLianXi\":\"13715060892\",\r\n" + 
			"            \"CanJiRenZhengHao\":\"44030619811218002X42\",\r\n" + 
			"            \"YueShouRu\":\"3800\"\r\n" + 
			"        }\r\n" + 
			"    ]\r\n" + 
			"}]";
	// 复杂格式json字符串
	private static final String COMPLEX_JSON_STR = "{\"teacherName\":\"crystall\",\"teacherAge\":27,\"course\":{\"courseName\":\"english\",\"code\":1270},\"students\":[{\"studentName\":\"lily\",\"studentAge\":12},{\"studentName\":\"lucy\",\"studentAge\":15}]}";

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		// demoJson();

		 testJSONStrToJSONObject();//json字符串转化对象
//		 testJSONStrToJSONArray();//json数组转化json对象
		//testComplexJSONStrToJSONObject();// json对象嵌套json对象
	}

	/**
	 * 复杂json格式字符串与JSONObject之间的转换
	 */
	
	
//	public static void testComplexJSONStrToJSONObject() {
//		System.out.println(COMPLEX_JSON_STR);
//		JSONObject jsonObject = JSON.parseObject(COMPLEX_JSON_STR); // JSONObject jsonObject1 = //
//		JSONObject.parseObject(COMPLEX_JSON_STR);// 因为JSONObject继承了JSON，所以这样也是可以的
//		System.out.println(jsonObject);
//		String teacherName = jsonObject.getString("teacherName");
//		Integer teacherAge = jsonObject.getInteger("teacherAge");
//		JSONObject course = jsonObject.getJSONObject("course");
//		JSONArray students = jsonObject.getJSONArray("students");
//		System.out
//				.println(teacherName + "------" + teacherAge + "===json对象====" + course + "----json数组----" + students);
//		JSONArray jsonArray = JSON.parseArray(students.toString());
//		System.out.println(jsonArray);
//	}
	 

	/**
	 * json字符串-数组类型与JSONArray之间的转换
	 */
	public static void testJSONStrToJSONArray() {
		
		JSONArray jsonArray = JSON.parseArray(JSON_ARRAY_STR);
		// JSONArray jsonArray1 =
		// JSONArray.parseArray(JSON_ARRAY_STR);//因为JSONArray继承了JSON，所以这样也是可以的

		// 遍历方式1
		int size = jsonArray.size();
		for (int i = 0; i < size; i++) {
			JSONObject jsonObject = jsonArray.getJSONObject(i);
			System.out.println(jsonObject.getString("ZhuCeLeiXing") );
			System.out.println(jsonObject.getString("LiShuGuanXi") );
			JSONArray jsonArrayData= jsonObject.getJSONArray("drow20181999103670645");
			int sizes=jsonArrayData.size();
			  for (int j = 0; j <sizes ; j++) {
				  JSONObject jsonObjectData = jsonArrayData.getJSONObject(j);
				  System.out.println(jsonObjectData.getString("ShenFenZhengHao") );
			  
			 
			  }
			 
		}

		// 遍历方式2
		/*
		 * for (Object obj : jsonArray) { JSONObject jsonObject = (JSONObject) obj;
		 * System.out.println(jsonObject.getString("studentName") + ":" +
		 * jsonObject.getInteger("studentAge")); }
		 */
	}

	/**
	 * json字符串-简单对象型与JSONObject之间的转换
	 */
	
	public static void testJSONStrToJSONObject() {

		JSONObject jsonObject = JSON.parseObject(JSON_OBJ_STR); // JSONObject

		System.out.println(jsonObject.getString("ZhuCeLeiXing"));
		System.out.println(jsonObject.getString("LiShuGuanXi"));
		JSONArray jsonArrayData = jsonObject.getJSONArray("drow20181999103670645");
		int sizes = jsonArrayData.size();
		for (int j = 0; j < sizes; j++) {
			JSONObject jsonObjectData = jsonArrayData.getJSONObject(j);
			System.out.println(jsonObjectData.getString("ShenFenZhengHao"));

		}
	}
	  
//	public static void demoJson() {
//
//		/**
//		 * 将 Json 形式的字符串转换为 Map
//		 */
//
//		String str = "{\"name\":\"Tom\",\"age\":90}";
//		JSONObject jsonObject = JSONObject.parseObject(str);
//		Map<String, String> params = JSONObject.parseObject(jsonObject.toString(),
//				new TypeReference<Map<String, String>>() {
//				});
//		System.out.println(params);
//
//		/**
//		 * 将 Json 形式的字符串转换为 JavaBean
//		 */
//		str = "{\"id\":\"A001\",\"name\":\"Jack\"}";
//		jsonObject = JSONObject.parseObject(str);
//		System.out.println(jsonObject);
//		Person person = JSON.parseObject(str, new TypeReference<Person>() {
//		});
//		System.out.println(person.toString());
//	}
			 
	
	
}


